import java.util.StringJoiner;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/16 15:58
 * @description:
 */
public class Solution557 {
    public String reverseWords(String s) {
        String []splits =s.split("\\s");
        String []reverseSplits =new String[splits.length];
        for (int i = 0; i < splits.length; i++) {
            reverseSplits[i] = new StringBuilder(splits[i]).reverse().toString();
        }
        return String.join(" ",reverseSplits);
    }
    public String reverseWords2(String s) {
        StringJoiner sj=new StringJoiner(" ");
        String[] ss =s.split(" ");
        for(String i:ss) {
            sj.add(new StringBuilder(i).reverse());
        }
        return sj.toString();
    }

    public static void main(String[] args) {
        Solution557 solution = new Solution557();
        System.out.println(solution.reverseWords("Let's take LeetCode contest"));
        System.out.println(solution.reverseWords("Mr Ding"));
    }
}
